import pyautogui

import pyperclip as clip

from jsjj.util.logUtil import *
from jsjj.util.timeUtil import *


def closePOPTOPFIX():
    pyautogui.moveTo(1023, 289, 2)
    sleep(2)

    pyautogui.scroll(10000)

    # 关闭顶部广告菜单
    pyautogui.moveTo(1571, 135, 2)
    pyautogui.click()
    sleep(1)


def closeF12AtLastStep():
    sleep(2)
    pyautogui.moveTo(1399, 383, 2)

    # 关闭F12显示
    sleep(2)
    pyautogui.keyDown('f12')
    pyautogui.keyUp('f12')

    sleep(2)
    pyautogui.scroll(10000)
    return


def resetGuiAtLastStepCloseF12ToTop():
    # 关闭F12显示, 拼多多
    sleep(4)
    pyautogui.keyDown('f12')
    pyautogui.keyUp('f12')

    sleep(4)
    pyautogui.moveTo(1634, 690, 4)
    sleep(2)
    pyautogui.scroll(50000)
    sleep(2)
    return


# 1920*1080 分辨率
def viaCommonUrl(url):
    sleep(2)

    pyautogui.moveTo(811, 130, 2)
    pyautogui.click()

    pyautogui.moveTo(430, 55, 3)
    pyautogui.click()

    sleep(1)

    clip.copy(url)  # 先复制

    sleep(2)
    pyautogui.hotkey('ctrl', 'a')

    sleep(2)
    pyautogui.hotkey('ctrl', 'v')

    sleep(1)
    pyautogui.hotkey('enter')

    pyautogui.moveTo(909, 342, 2)

    pyautogui.scroll(1000)

    return


def getSjhtShopName():
    # ★★★★★★★★为了获取店铺名称，直接获取的用户名称
    sleep(4)
    pyautogui.moveTo(1007, 226, 2)
    pyautogui.scroll(10000)
    pyautogui.moveTo(1299, 129, 4)

    pyautogui.moveTo(1309, 186, 2)

    pyautogui.click()

    sleep(2)
    pyautogui.keyDown('f12')
    pyautogui.keyUp('f12')

    sleep(2)
    pyautogui.keyDown('f5')
    pyautogui.keyUp('f5')

    # ==============F12的filter过滤框
    pyautogui.moveTo(1571, 167, 6)
    pyautogui.doubleClick()

    # 过滤
    clip.copy('userinfo')  # 先复制
    pyautogui.hotkey('ctrl', 'v')  # 再粘贴

    # 选中过滤文件
    pyautogui.moveTo(1540, 325, 4)
    pyautogui.click()

    # 点中json值区域
    pyautogui.moveTo(1812, 497, 4)
    pyautogui.click()

    sleep(2)
    pyautogui.hotkey('ctrl', 'a')

    sleep(2)
    pyautogui.hotkey('ctrl', 'c')

    # bug fix，到第一个页面可能会被遮住
    pyautogui.moveTo(1571, 167, 2)

    # 读取剪切板内容queryGoodsPageRT
    sleep(2)
    value = clip.paste()
    jsonFromWebShopName = json.loads(value)

    fixBugPopWinAfterF12()

    # 关闭页签
    sleep(4)
    pyautogui.hotkey('ctrl', 'w')

    #  ★★★★★★★★★

    return jsonFromWebShopName

def fixBugPopWinAfterF12():
    # 按了F5之后的
    pyautogui.moveTo(1368, 662, 4)
    pyautogui.click()

    for i in range(0, 40):
        pyautogui.moveTo(1368, 568 + i * 10, 0.2)
        pyautogui.click()
    sleep(1)
    return


def P_HT_FixGUIBug():
    pyautogui.moveTo(1330, 228, 4)
    pyautogui.click()
    sleep(1)


def fixBugPOP():
    # bug fix
    sleep(4)
    pyautogui.moveTo(1015, 259, 2)

    # 对pop的弹出广告处理，就直接没法处理了。
    # 顶部广告（x掉，又会影响正常的运行）
    # pyautogui.moveTo(1361, 135, 2)
    # pyautogui.click()
    sleep(1)
    return

def P_HT_FixGUIBug():
    pyautogui.moveTo(1330, 228, 4)
    pyautogui.click()
    sleep(1)